<?php 

namespace Acme\ContestBundle\Form;
 
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class CtInfoType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
    	$builder->add('name', 'text', array('label' => '竞赛名称'));
		$builder->add('contestType', 'contestTypeSelector');
		//$builder->add('birth', 'date', array('label' => '生日', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd',));  // , 'read_only' => true
    	
    	if (in_array('ROLE_SUPER_ADMIN', $options['role'])) {
    		$builder->add('university', 'universitySelector', array('property_path' => false));
    		$builder->add('applyBy', 'teacherSelector', array('label' => '申请人'));
    	}
    }
    
    // the name of the class that holds the underlying data(for use of function createForm)
    public function getDefaultOptions(array $options)
    {
    	if ($options['build_for'] == 'regist') {
    		return array(
    				'build_for' => $options['build_for'],
    				'data_class' => 'Acme\ContestBundle\Entity\CtInfo',
    				'validation_groups' => array('regist_default', 'regist_' . $options['category_name']),
    				'category_name' => $options['category_name'],
    				'required' => false,
    		);
    	} elseif ($options['build_for'] == 'edit') {
    		return array(
    				'build_for' => $options['build_for'],
   					'data_class' => 'Acme\ContestBundle\Entity\CtInfo',
   					'required' => false,
    				'role' => $options['role'],
    		);
    	}
    }
    
    // note that the getName() method should return a unique identifier for this form "type"
    public function getName()
    {
    	return 'ct_info';
    }
}